#include "day9.h"
#include <QApplication>

#include <osgDB/ReadFile>
#include <osg/MatrixTransform>
#include <osgGA/NodeTrackerManipulator>
#include <osgGA/TrackballManipulator>
#include <CommonLib/MainWindow/MainWindow.h>
#include <CommonLib/ListWidget/ListWidget.h>
#include <CommonLib/Manupulator/ManupulatorTest.h>

int day9( int argc, char **argv )
{
    QApplication app(argc, argv);
    CMainWindow mainWindow;
    CListWidget listWidget(&mainWindow);

    osg::ref_ptr<osg::Node> rpNode = osgDB::readNodeFile("cow.osg");
    osg::ref_ptr<osg::MatrixTransform> rpMt = new osg::MatrixTransform;
    rpMt->addChild(rpNode);
    rpMt->setMatrix(osg::Matrix::translate(-15.0, 0.0, 0.0) );
    listWidget.addModel("rightModel", rpMt.get() );

    osgViewer::View::EventHandlers EventHandlers = mainWindow.getViewer()->getEventHandlers();
    auto itrHandle = EventHandlers.begin();
    for (; itrHandle != EventHandlers.end(); itrHandle++)
    {
        mainWindow.getViewer()->removeEventHandler(*itrHandle);
    }
    osg::ref_ptr< CDriveManupulator> rpDriveMp = new CDriveManupulator();
    mainWindow.getViewer()->setCameraManipulator(rpDriveMp.get()/*new osgGA::TrackballManipulator()*/ );
    listWidget.addModel("TrevelBall", rpDriveMp->getBallNode() );
    //end

    mainWindow.home();
    mainWindow.setGeometry( 560, 240, 800, 600 );
    mainWindow.show();

    return app.exec();
}
